/**
 * 
 */
package ru.olympus.antonyhands.ao.client.widgets;

import java.util.List;

import ru.olympus.antonyhands.ao.client.AOHelperServiceAsync;
import ru.olympus.antonyhands.ao.shared.util.StringPair;

import com.google.gwt.user.client.rpc.AsyncCallback;

/**
 * @author AntonyHands
 * @since 15.02.2012
 */
public class ItemCategoriesListBox extends BasicListBox
{
    public ItemCategoriesListBox(AOHelperServiceAsync service)
    {
    	super(service, null);
        refreshItemsList();
    }

    public ItemCategoriesListBox(AOHelperServiceAsync service, String defaultValue)
    {
    	super(service, defaultValue);
        refreshItemsList();
    }

    private void refreshItemsList()
    {
        getService().listItemCategories(new AsyncCallback<List<StringPair>>()
        {
            @Override
            public void onSuccess(List<StringPair> result)
            {
                clear();
                for (StringPair pair : result)
                    addItem(pair.getValue(), pair.getKey());
                updateCurrentValue();
            }

            @Override
            public void onFailure(Throwable caught)
            {
                clear();
                //TODO: сделать что-нибудь
            }
        });
    }

}
